// pages/teacher/live-room/live-room.js
import { courses } from '../../../utils/mockData.js'

Page({
  data: {
    course: null,
    isLive: true,
    viewers: 0,
    messages: [],
    inputValue: '',
    whiteboardEnabled: false
  },
  onLoad(options) {
    const courseId = parseInt(options.courseId)
    const course = courses.find(c => c.id === courseId)
    if (course) {
      this.setData({ course })
    }
  },
  onShow() {
    this.startLive()
  },
  onHide() {
    this.stopLive()
  },
  startLive() {
    // 开始直播
    wx.setNavigationBarTitle({
      title: this.data.course.title + ' - 直播中'
    })
    this.updateViewers()
  },
  stopLive() {
    // 结束直播
  },
  updateViewers() {
    // 模拟更新观看人数
    this.setData({
      viewers: 1234 + Math.floor(Math.random() * 100)
    })
  },
  toggleWhiteboard() {
    this.setData({
      whiteboardEnabled: !this.data.whiteboardEnabled
    })
  },
  endLive() {
    wx.showModal({
      title: '结束直播',
      content: '确定要结束当前直播吗？',
      success: (res) => {
        if (res.confirm) {
          wx.navigateBack()
        }
      }
    })
  },
  onShare() {
    wx.showShareMenu({
      withShareTicket: true
    })
  }
})
